<?php
/**
 * @file Wiki.php
 *
 * A parser for Wiki-Markup.
 *
 * This class can parse from Wiki-Markup to HTML and the other way around.
 *
 * http://code.google.com/p/rpd/wiki/Wiki.php
 *
 * New BSD License
 * \n
 * Copyright (c) 2010 Rpd-Team
 *
 * @namespace  rpd
 * @since      0.0.1
 * @version    0.0.1
 */

/**
 *
 */

define("RPD_WIKI_AUTO", 1);
define("RPD_WIKI_HTML", 2);
define("RPD_WIKI_TEXT", 4);

class Wiki {

	private $_content = "";

	function __construct($content = "", $mode = RPD_WIKI_AUTO) {
		if ($mode == RPD_WIKI_HTML || strip_tags($content, '<br />') != $content)
		{
			$mode = RPD_WIKI_HTML;

			$content = str_replace('<br />', "\r\n", $content);
		}
		else
		{
			$mode = RPD_WIKI_TEXT;
			$content = htmlspecialchars($content);

			$content = nl2br($content, true);
			$content = str_replace("\r", "", $content);
			$content = str_replace("\n", "", $content);
		}

		$this->_content = $content;

	}

	function __toString()
	{
		return $this->_content;
	}
}

?>